<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
	</head>
	<body>
		<form>
			<div>
				<input type="text" name="account" placeholder="请输入账号" />
			</div>
			<div>
				<input type="password" name="password" placeholder="请输入密码" />
			</div>
			<div>
				<button type="button" onclick="save()">注册</button>
			</div>
		</form>
		
		<script type="text/javascript">
			function save() {
				let input_account = document.getElementsByName("account")[0];
				let input_password = document.getElementsByName("password")[0];
				
				let account = input_account.value;
				let password = input_password.value;
				
				//支持多用户注册
				// let user = {account, password};//ES6支持的简写方式
				let user = {account: account, password: password};
				//放到一个数组中
				let users = localStorage.getItem("users");
				console.log(typeof users);
				console.log(users);
				if(!users) {
					users = [];
				}else {
					users = JSON.parse(users);
				}
				console.log(users);
				users.push(user);
				// //将数组保存到localStorage中
				localStorage.setItem("users", JSON.stringify(users));
			}
		</script>
	</body>
</html>
